package com.zyd.blog.personal.controller;

import java.sql.Blob;
import java.util.*;

import com.alibaba.fastjson.JSONObject;
import com.zyd.blog.personal.enuminterface.Step;
import com.zyd.blog.personal.enuminterface.UserType;
import com.zyd.blog.personal.po.CompanyInfoPo;
import com.zyd.blog.personal.service.*;
import com.zyd.blog.personal.utils.JavaBeanToJsonUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 测试Controller
 * @author mfy
 */
@RestController
public class TestController {

    @Resource
    private ProtocolService protocolService;

    @Resource
    private MyCompanyInfoService myCompanyInfoService;

    @Resource
    private UserInfoService userInfoService;

    @Resource
    private UserNoService userNoService;

    @Resource
    private UserApplyDesignTempService userApplyDesignTempService;

    @Resource
    private UserCompanyService userCompanyService;

    /**
     * 添加协议
     * 访问路径 : http://localhost:8443/addProtocolInfo
     * @return  结果
     */
    @RequestMapping("/addProtocolInfo")
    public Object addProtocolInfo(){
        return protocolService.addProtocolInfoByJson();
    }

    /**
     * 得到协议
     * 访问路径 : http://localhost:8443/getProtocol?type=
     * @return  结果
     */
    @RequestMapping("/getProtocol")
    public Object getProtocol(String type){
        return protocolService.queryProtocolByCondition(type);
    }

    /**
     * 添加公司信息
     * 访问路径 : http://localhost:8443/addMyCompanyInfo
     */
    @RequestMapping("/addMyCompanyInfo")
    public Object addMyCompanyInfo() {
//        Map<String,Object> condition = new HashMap<>(16);
//        condition.put("model","cooperationDescription");
//
//        List<Map<String,Object>> p1 = JavaBeanToJsonUtils.getParagraph(new ArrayList<> (),"我们的优势","我们的优势内容");
//        String advantage = JavaBeanToJsonUtils.javaBeanToJson("",p1);
//        condition.put("advantage",advantage);
//
//        List<Map<String,Object>> p2 = JavaBeanToJsonUtils.getParagraph(new ArrayList<> (),"说明","说明内容");
//        String description = JavaBeanToJsonUtils.javaBeanToJson("",p2);
//        condition.put("description",description);
//
//        List<Map<String,Object>> p3 = JavaBeanToJsonUtils.getParagraph(new ArrayList<> (),"申请步骤","申请步骤的内容");
//        String process = JavaBeanToJsonUtils.javaBeanToJson("",p3);
//        condition.put("process",process);
//
//        condition.put("telephone","12345678987");
//        condition.put("email","qq@qq.com");
//        condition.put("url","www.baidu.com");
//        condition.put("protocol","MerchantCooperation");
//        condition.put("photo","photo");
//        return myCompanyInfoService.addMyCompanyInfo(condition);
        return false;
    }

    /**
     * 得到公司信息
     * 访问路径 :   http://localhost:8443/getMyCompanyInfo?id=&model=
     * @param id    信息id
     * @param model 信息模块
     * @return  信息
     */
    @RequestMapping("/getMyCompanyInfo")
    public Object getMyCompanyInfo(Long id,String model){
        CompanyInfoPo result = myCompanyInfoService.getMyCompanyInfo(id,model);
        System.out.println(result);

        return result;
    }

    /**
     * 得到公司信息
     * 访问路径 :   http://localhost:8443/getAdvantage?id=
     * @param id    信息id
     * @param model 信息模块
     * @return  信息
     */
    @RequestMapping("/getAdvantage")
    public Object getAdvantage(Long id,String model){
        CompanyInfoPo result = myCompanyInfoService.getMyCompanyInfo(id,model);
        System.out.println(result.getAdvantage());
        JSONObject json = JSONObject.parseObject(result.getAdvantage());
        System.out.println(json);
        return json;
    }


    /**
     * 访问路径 http://localhost:8443/reViewApplyDesign?userId=4&result=1&reason=fasfd
     * @param userId    用户id
     * @param result    1为通过,2位不通过
     * @param reason    审核原因
     * @return  结果
     */
    @RequestMapping("/reViewApplyDesign")
    public Object reViewApplyDesign(Long userId,Integer result,String reason,String reviewName){
        if(userId == null){
            return false;
        }
        if(result == null){
            return false;
        }
        return userApplyDesignTempService.reViewApplyDesign(null,userId,result,reason,reviewName);
    }

}
